/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.composite;

import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;

import com.cea.papyrus.core.editor.DiagramPalette;
import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editor.abstracteditor.AbstractGraphicalPageWithFlyoutPalette;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;

/**
 * Main class for the editor for composite diagrams
 */
public class CompositeEditor extends AbstractGraphicalPageWithFlyoutPalette 
implements /*DiagramEditorPage,*/ ITabbedPropertySheetPageContributor {

	/** Palette for the composite diagram */
	private static DiagramPalette PALETTE_MODEL;    

	/**
	 * Creates a new CompositeEditor.
	 * @param diagram the diagram that is a composite diagram
	 * @param modelMngr the modelManager associated to the editor
	 */
	public CompositeEditor( Diagram diagram, ModelManager modelMngr){
		super( diagram, modelMngr);
	}

	/**
	 * Creates a new CompositeEditor, with a specified editing domain.
	 * @param diagram the diagram displayed by this editor
	 * @param modelMngr the model manager associated to the multi-diagram editor
	 * @param commandStack the command stack shared among all editors of a multiDiagramEditor
	 */
	public CompositeEditor( Diagram diagram, ModelManager modelMngr, CommandStack commandStack, ActionRegistry actionRegistry){//, ModelResourceManager resourceManager){
		super( diagram, modelMngr, commandStack, actionRegistry);
	}

	/**
	 * Returns the singleton instance of the palette root. It creates it if needed.
	 * @return the palette root for this editor.
	 */
	@Override
	protected PaletteRoot getPaletteRoot() {
		if (PALETTE_MODEL == null) {
			PALETTE_MODEL = CompositePaletteFactory.createPalette();
		}
		return PALETTE_MODEL;
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.editor.abstracteditor.AbstractGraphicalPageWithFlyoutPalette#configureGraphicalViewer()
	 */
	@Override
	protected void configureGraphicalViewer() {
		super.configureGraphicalViewer();
		viewer = getGraphicalViewer();
		
		// Create and register the EditPartFactory
		viewer.setEditPartFactory(new CompositeGraphicalEditPartsFactory(modelMngr));

		// configure the context menu provider
		cmProvider = new CompositeContextMenuProvider(viewer, getActionRegistry(),modelMngr);
		super.configureContextMenuProvider();
	}
}
